import 'package:flutter/material.dart';
import 'package:flutter_demo/start_up/function_widgets/alerts/0x00_aleret_item.dart';
import 'package:flutter_demo/start_up/function_widgets/alerts/0x01_alert_dialog_routes.dart';

class ListDialogPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {

    ////////////////////////////////////////////////////////////////////////

    _showListDialogAction() async {
      int index = await showDialog<int>(
        context: context,
        builder: (context) {
          var alertChild = Column(
            children: <Widget>[
              ListTile(
                title: Text("Please Chooice"),
              ),
              Expanded(
                child: ListView.builder(
                  itemCount: 30,
                  itemBuilder: (ctx, index) {
                    return ListTile(
                      title: Text("$index"),
                      onTap: () => Navigator.of(ctx).pop(index),
                    );
                  },
                ),
              )
            ],
          );


          // 会报错
          // return AlertDialog(content: alertChild);


          // return Dialog(
          //   child: alertChild,
          // );


          // 同上
          return UnconstrainedBox(
            constrainedAxis: Axis.vertical,
            child: ConstrainedBox(
              constraints: BoxConstraints(
                maxWidth: 280,
              ),
              child: Material(
                child: alertChild,
                type: MaterialType.card,
              ),
            ),
          );
        },
      );

      if (index != null) {
        alert(context, content: "Clicked at: $index");
      }
    }
  
    void _showListDialog() {
      _showListDialogAction();
    }






    return Scaffold(
      appBar: AppBar(
        title: Text("List Dialog"),
      ),
      body: Padding(
        padding: EdgeInsets.only(
          top: 18,
          bottom: 18
        ),
        child: ListView(
          children: <Widget>[
            AlertItem("text", _showListDialog)
          ],
        ),
      ),
    );
  }
}